package com.yanq.liancar.activity;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.google.gson.Gson;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;

import com.vondear.rxtool.view.RxToast;
import com.yanq.liancar.R;
import com.yanq.liancar.activity.base.BaseToolbarActivity;
import com.yanq.liancar.adapter.BOrderListAdapter;
import com.yanq.liancar.adapter.RescueRecordAdapter;
import com.yanq.liancar.bean.GetRescueRecordListBean;
import com.yanq.liancar.bean.UserBean;
import com.yanq.liancar.bean.loginUserBean;
import com.yanq.liancar.url.Config;
import com.yanq.liancar.util.LogUtils;
import com.yanq.liancar.util.Utils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class SmallCRescueRecordActivity extends BaseToolbarActivity {
    @BindView(R.id.imageView)
    ImageView imageView;
    @BindView(R.id.tv_title111)
    TextView tvTitle;
    @BindView(R.id.rl_title)
    RelativeLayout rlTitle;
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.tv_phone)
    TextView tvPhone;
    @BindView(R.id.tv_time)
    TextView tvTime;
    @BindView(R.id.Tv_already_evaluate)
    TextView TvAlreadyEvaluate;
    @BindView(R.id.Tv_go_evaluate)
    TextView TvGoEvaluate;
    @BindView(R.id.rescue_recyclerview)
    RecyclerView recyclerview;
    @BindView(R.id.ll_title)
    LinearLayout ll_title;
    private List<GetRescueRecordListBean.DataBean> mList = new ArrayList<>();
    private RescueRecordAdapter adapter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_small_rescuerecord);
        Utils.setStatusBar(this, true, false);
        ButterKnife.bind(this);
        mTvTitle.setText("救援记录");
        initRecyclerview();
        initOkGo();

    }

    @OnClick({R.id.Tv_go_evaluate})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.Tv_go_evaluate:
                break;
        }
    }

    private void initRecyclerview() {
        recyclerview.setNestedScrollingEnabled(false);
        recyclerview.setLayoutManager(new LinearLayoutManager(mContext));
        adapter = new RescueRecordAdapter(R.layout.item_evaluate, mList);
        recyclerview.setAdapter(adapter);

        adapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
            @Override
            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                switch (view.getId()) {
                    case R.id.Tv_go_evaluate:
                        if (mList.get(position).getStatus() == 0) {
                            //去评价

                        }
                }
            }
        });
    }

    private void initOkGo() {
        OkGo.<String>post(Config.s + "llc/api/RoadRescueController/selectUserRescueRecords")
                .tag(this)
                .params("token", UserBean.getcToken(this))
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        Gson gson = new Gson();
                        GetRescueRecordListBean bean = gson.fromJson(response.body(), GetRescueRecordListBean.class);
                        if (bean.isIsSuccess()) {
                            if (bean.getCode() == 200) {
                                ll_title.setVisibility(View.VISIBLE);
                                tvName.setText(bean.getData().get(0).getRescue_name());
                                tvTitle.setText(bean.getData().get(0).getRescue_result());
                                tvPhone.setText(bean.getData().get(0).getRescue_tel());
                                tvTime.setText(bean.getData().get(0).getTime());
                                if (bean.getData().get(0).getStatus() == 0) {
                                    TvAlreadyEvaluate.setVisibility(View.GONE);
                                    TvGoEvaluate.setVisibility(View.GONE);
                                    TvGoEvaluate.setText("去评价>>");
                                } else {
                                    TvAlreadyEvaluate.setVisibility(View.GONE);
                                    TvGoEvaluate.setVisibility(View.GONE);
                                    TvAlreadyEvaluate.setText("已评价");
                                }
                                mList.clear();
                                mList.addAll(bean.getData());
                                mList.remove(0);
                                adapter.setNewData(mList);
                            } else {
                                ll_title.setVisibility(View.GONE);
                                RxToast.info(bean.getOutputMessage());
                            }
                        } else {
                            RxToast.error(bean.getOutputMessage());
                        }

                    }
                });
    }
}
